﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Common;
using System.Web.SessionState;
using System.Dynamic;
using Model;
using DAL;
using System.Data;
using System.Dynamic;
using System.Net;
using System.Text;
using System.Web.SessionState;
using JPushAPI;
using System.Security.Cryptography;

namespace UI.tools
{
    /// <summary>
    /// Admin 的摘要说明
    /// </summary>
    public class Admin : IHttpHandler, IRequiresSessionState
    {
        static Dictionary<string, Func<int, string>> hs = new Dictionary<string, Func<int, string>>();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = JobRequest.GetRequestString("act");
            string result = string.Empty;
            if (Commons.CheckSign())
            {
                int adminid = 0;
                if (B.MyAdmin != null)
                {
                    adminid=B.MyAdmin.ID;
                }
                result = hs[action](adminid);
            }
            else
            {
                result = Commons.GetFaild("身份验证失败");
            }
            context.Response.Write(result);
            context.Response.End();
        }
        static Admin()
        {
            /*后台登陆*/
            #region 获取管理员列表
            hs.Add("Find_Admin", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<AdminInfo> list = AdminDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存管理员
            hs.Add("Save_Admin", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string realname = JobRequest.GetRequestString("realname"); //真是姓名
                string userpwd = DESEncrypt.Encrypt(JobRequest.GetRequestString("userpwd")); //密码
                string power = JobRequest.GetRequestString("power"); //权限
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = id,
                    UserName = username,
                    UserPwd = userpwd,
                    RealName = realname,
                    Power = power,
                    CreateDate = DateTime.Now,
                };
                if (id == 0)
                {
                    ID = AdminDAL.Save(info);
                    int newstypeid = NewsTypeDAL.Save(new NewsTypeInfo(){AdminID = ID,Name = "最新资讯",Sort = 1});
                    CommonDAL.UpdateColumnByID(ID, "Notice", "1&1&6&" + newstypeid + "&最新资讯", "[admin]");
                    TagsDAL.Save(new TagsInfo() { AdminID = ID, Name = "新品上市", Count = 4, Sort = 1, IsTop = 1 });
                    TagsDAL.Save(new TagsInfo() { AdminID = ID, Name = "热门推荐", Count = 4, Sort = 2, IsTop = 1 });
                }
                else
                {
                    ID = AdminDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 后台登陆
            hs.Add("Login", (int adminid) =>
            {
                //参数
                try
                {
                    string username = JobRequest.GetRequestString("username"); //用户名
                    string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                    bool rememberme = JobRequest.GetRequestBool("rememberme"); //是否记住密码
                    int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                    //参数
                    AdminInfo info = AdminDAL.Login(username, DESEncrypt.Encrypt(userpwd));
                    if (info.ID > 0)
                    {
                        if (source == 1 || source == 0)
                        {
                            B.MyAdmin = info;
                        }
                        if (rememberme)
                        {
                            CookieHelper.WriteCookie("admin_username", username, 43200);
                            CookieHelper.WriteCookie("admin_userpwd", userpwd, 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "true", 43200);
                        }
                        else
                        {
                            CookieHelper.WriteCookie("admin_username", "", 43200);
                            CookieHelper.WriteCookie("admin_userpwd", "", 43200);
                            CookieHelper.WriteCookie("admin_rememberme", "false", 43200);
                        }
                        
                        return Commons.GetSuccess("登陆成功", info);
                    }
                    else
                    {
                        return Commons.GetFaild("用户名或密码错误");
                    }
                }
                catch (Exception ex)
                {
                    return Commons.GetFaild(ex.Message);
                }
            });
            #endregion
            #region 修改密码
            hs.Add("Update_Pwd", (int adminid) =>
            {
                //参数
                int userid = JobRequest.GetRequestInt("userid"); //用户ID
                string oldpwd = JobRequest.GetRequestString("oldpwd"); //旧密码
                string newpwd = JobRequest.GetRequestString("newpwd"); //新密码
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                AdminInfo user = new AdminInfo();
                if (source == 1 || source == 0)
                {
                    user = B.MyAdmin;
                }
                else
                {
                    user = AdminDAL.FindOneByID(userid);
                }

                if (user.UserPwd != oldpwd)
                {
                    return Commons.GetFaild("旧密码错误");
                }
                bool ok = CommonDAL.UpdateColumnByID(user.ID, "userpwd", DESEncrypt.Encrypt(newpwd), "[admin]");
                if (ok)
                {
                    if (source == 1 || source == 0)
                    {
                        B.MyAdmin.UserPwd = newpwd;
                    }
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 删除管理员
            hs.Add("Delete_Admin", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 设置权限
            hs.Add("Power_Admin", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //用户ID
                string power = JobRequest.GetRequestString("power"); //权限，用户id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.UpdateColumnByID(id, "Power", power, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("设置成功", "");
                }
                else
                {
                    return Commons.GetFaild("设置失败");
                }
            });
            #endregion

            /*用户*/
            #region 获取用户列表
            hs.Add("Find_User", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<UserInfo> list = UserDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion           
            #region 保存用户
            hs.Add("Save_User", (int adminid) =>
            {

                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string username = JobRequest.GetRequestString("username"); //用户名
                string userpwd = JobRequest.GetRequestString("userpwd"); //密码
                string realname = JobRequest.GetRequestString("realname"); //真实姓名
                string sex = JobRequest.GetRequestString("sex"); //性别
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                UserInfo info = new UserInfo()
                {
                    ID = id,
                    UserName=username,
                    UserPwd = DESEncrypt.Encrypt(userpwd),
                    RealName=realname,
                    Sex = sex,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = UserDAL.Save(info);
                }
                else
                {

                    ID = UserDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除用户
            hs.Add("Delete_User", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[user]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion
            #region 导出用户
            hs.Add("Export_User", (int adminid) =>
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("姓名");
                dt.Columns.Add("手机号");
                List<UserInfo> list = UserDAL.FindAll();
                foreach (UserInfo info in list)
                {
                    DataRow dr = dt.NewRow();
                    dr["姓名"] = info.RealName;
                    dr["手机号"] = info.Mobile;
                    dt.Rows.Add(dr);
                }
                Common.ExcelHelper.DataTableToExcel(dt, "用户手机号-" + DateTime.Now.ToString("yyyy-MM-dd"));
                return Commons.GetSuccess("导出成功", "");
            });
            #endregion


            /*客服*/
            #region 获取客服
            hs.Add("Find_Kf", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<KfInfo> list = KfDAL.FindPage(keyword, adminid, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存客服
            hs.Add("Save_Kf", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //客服姓名
                string mobile = JobRequest.GetRequestString("mobile"); //客服电话
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                KfInfo info = new KfInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Mobile = mobile,
                    Name = name
                };
                if (id == 0)
                {
                    ID = KfDAL.Save(info);
                }
                else
                {

                    ID = KfDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除客服
            hs.Add("Delete_Kf", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[kf]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*广告*/
            #region 获取广告
            hs.Add("Find_Ad", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<AdInfo> list = AdDAL.FindPage(keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存广告
            hs.Add("Save_Ad", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int newsid = JobRequest.GetRequestInt("newsid"); //资讯ID
                string name = JobRequest.GetRequestString("name"); //名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string link = JobRequest.GetRequestString("link"); //链接
                int position = JobRequest.GetRequestInt("position"); //位置
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                DateTime begindate = JobRequest.GetRequestDateTime("begindate", DataConvert.DefaultDateTimeValue);
                DateTime enddate = JobRequest.GetRequestDateTime("enddate", DataConvert.DefaultDateTimeValue);
                int froms = JobRequest.GetRequestInt("froms"); //文章来源   1.自定义内容  2.从文章中选
                string context = JobRequest.GetRequestString("context"); //内容
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                AdInfo info = new AdInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    NewsID = newsid,
                    Name = name,
                    Img = img,
                    Link = link,
                    Position = position,
                    Sort = sort,
                    BeginDate = begindate,
                    EndDate = enddate,
                    Froms = froms,
                    Context = context,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = AdDAL.Save(info);
                }
                else
                {

                    ID = AdDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除广告
            hs.Add("Delete_Ad", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[ad]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*分类*/
            #region 获取分类
            hs.Add("Find_Category", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<CategoryInfo> alllist = CategoryDAL.FindAll(adminid);
                List<CategoryInfo> parentlist = alllist.Where(x => x.ParentID == 0).ToList();
                List<CategoryInfo> list = new List<CategoryInfo>();
                foreach (CategoryInfo menu in parentlist)
                {
                    list.Add(menu);
                    list.AddRange(alllist.Where(x => x.ParentID == menu.ID));
                }
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存分类
            hs.Add("Save_Category", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //分类名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                CategoryInfo info = new CategoryInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    ParentID = parentid,
                    Name = name,
                    Sort = sort,
                    Img = img != "" ? img : "/img/cate.png",
                };
                if (id == 0)
                {
                    ID = CategoryDAL.Save(info);
                }
                else
                {
                    ID = CategoryDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除分类
            hs.Add("Delete_Category", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[category]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*资讯*/
            #region 获取资讯
            hs.Add("Find_News", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<NewsInfo> list = NewsDAL.FindPage(0, keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存资讯
            hs.Add("Save_News", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //
                int newstypeid = JobRequest.GetRequestInt("newstypeid"); //
                string title = JobRequest.GetRequestString("title"); //标题
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string context = JobRequest.GetRequestString("context"); //内容
                int clickcount = JobRequest.GetRequestInt("clickcount"); //点击量
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                NewsInfo info = new NewsInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    NewsTypeID = newstypeid,
                    Title = title,
                    Img = img!=""?img:"/img/zixun.gif",
                    Context = context,
                    ClickCount = clickcount,
                    Sort = sort,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = NewsDAL.Save(info);
                }
                else
                {
                    ID = NewsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除资讯
            hs.Add("Delete_News", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[news]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*产品*/
            #region 获取产品
            hs.Add("Find_Product", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<ProductInfo> list = ProductDAL.FindPage(0,0,keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存产品
            hs.Add("Save_Product", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                int category1id = JobRequest.GetRequestInt("category1id"); //1级类别ID
                int category2id = JobRequest.GetRequestInt("category2id"); //2级类别ID
                string num = JobRequest.GetRequestString("num"); //产品编号
                string name = JobRequest.GetRequestString("name"); //产品名称
                string img = JobRequest.GetRequestString("img"); //产品图片
                float oprice = JobRequest.GetRequestFloat("oprice"); //原价
                float aprice = JobRequest.GetRequestFloat("aprice"); //市场价
                string unit = JobRequest.GetRequestString("unit"); //单位
                string tags = JobRequest.GetRequestString("tags"); //产品标签
                int sellcount = JobRequest.GetRequestInt("sellcount"); //销量
                string context = JobRequest.GetRequestString("context"); //产品详情
                int clickcount = JobRequest.GetRequestInt("clickcount"); //点击量
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                ProductInfo info = new ProductInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Category1ID = category1id,
                    Category2ID = category2id,
                    Num = num,
                    Name = name,
                    Img = img.Replace(Commons.domain,""),
                    OPrice = oprice,
                    APrice = aprice,
                    Unit = unit,
                    Tags = tags,
                    SellCount = sellcount,
                    Context = context,
                    ClickCount = clickcount,
                    Sort = sort,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = ProductDAL.Save(info);
                }
                else
                {
                    ID = ProductDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除产品
            hs.Add("Delete_Product", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[product]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*资讯分类*/
            #region 获取资讯分类
            hs.Add("Find_NewsType", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<NewsTypeInfo> list = NewsTypeDAL.FindPage(keyword, adminid, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存资讯分类
            hs.Add("Save_NewsType", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //
                string name = JobRequest.GetRequestString("name"); //分类名称
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                NewsTypeInfo info = new NewsTypeInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Sort = sort
                };
                if (id == 0)
                {
                    ID = NewsTypeDAL.Save(info);
                }
                else
                {
                    ID = NewsTypeDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除资讯分类
            hs.Add("Delete_NewsType", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[newstype]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*资质荣誉*/
            #region 获取资质荣誉
            hs.Add("Find_Honor", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<HonorInfo> list = HonorDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存资质荣誉
            hs.Add("Save_Honor", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                string name = JobRequest.GetRequestString("name"); //名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string context = JobRequest.GetRequestString("context"); //内容
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                HonorInfo info = new HonorInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Img = img,
                    Context = context,
                    Sort = sort,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = HonorDAL.Save(info);
                }
                else
                {
                    ID = HonorDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除资质荣誉
            hs.Add("Delete_Honor", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[honor]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*公司环境*/
            #region 获取公司环境
            hs.Add("Find_Environment", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<EnvironmentInfo> list = EnvironmentDAL.FindPage(adminid,keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存公司环境
            hs.Add("Save_Environment", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                string name = JobRequest.GetRequestString("name"); //名称
                string img = JobRequest.GetRequestString("img").Replace(Commons.domain, ""); //图片
                string context = JobRequest.GetRequestString("context"); //内容
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                EnvironmentInfo info = new EnvironmentInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Img = img,
                    Context = context,
                    Sort = sort,
                    CreateDate = DateTime.Now
                };
                if (id == 0)
                {
                    ID = EnvironmentDAL.Save(info);
                }
                else
                {
                    ID = EnvironmentDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除公司环境
            hs.Add("Delete_Environment", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[environment]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*留言反馈*/
            #region 获取留言反馈
            hs.Add("Find_Message", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<MessageInfo> list = MessageDAL.FindPage(keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 删除留言反馈
            hs.Add("Delete_Message", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[message]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*产品标签*/
            #region 获取产品标签
            hs.Add("Find_Tags", (int adminid) =>
            {
                //参数
                int page = JobRequest.GetRequestInt("page"); //第几页
                int limit = JobRequest.GetRequestInt("limit"); //每页条数
                string keyword = JobRequest.GetRequestString("keyword"); //搜索关键词
                string begindate = JobRequest.GetRequestString("begindate"); //开始时间
                string enddate = JobRequest.GetRequestString("enddate"); //结束时间
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<TagsInfo> list = TagsDAL.FindPage(adminid, keyword, begindate, enddate, page, limit, "", "", out count);
                return Commons.GetSuccess("获取成功", list, count);
            });
            #endregion
            #region 保存产品标签
            hs.Add("Save_Tags", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //唯一ID
                string name = JobRequest.GetRequestString("name"); //名称
                int count = JobRequest.GetRequestInt("count"); //获取条数
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐到首页
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                TagsInfo info = new TagsInfo()
                {
                    ID = id,
                    AdminID = adminid,
                    Name = name,
                    Count = count,
                    Sort = sort,
                    IsTop = istop
                };
                if (id == 0)
                {
                    ID = TagsDAL.Save(info);
                }
                else
                {
                    ID = TagsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除产品标签
            hs.Add("Delete_Tags", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[tags]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*菜单*/
            #region 获取菜单
            hs.Add("Find_Menu", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<MenuInfo> alllist = MenuDAL.FindAll();
                List<MenuInfo> parentlist = alllist.Where(x => x.ParentID == 0).ToList();
                List<MenuInfo> list = new List<MenuInfo>();
                foreach (MenuInfo menu in parentlist)
                {
                    list.Add(menu);
                    list.AddRange(alllist.Where(x => x.ParentID == menu.ID));
                }
                return Commons.GetSuccess("获取成功", list, list.Count);
            });
            #endregion
            #region 保存菜单
            hs.Add("Save_Menu", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int parentid = JobRequest.GetRequestInt("parentid"); //父ID
                string name = JobRequest.GetRequestString("name"); //菜单名称
                string path = JobRequest.GetRequestString("path"); //菜单路径
                string btns = JobRequest.GetRequestString("btns"); //按钮
                int sort = JobRequest.GetRequestInt("sort"); //排序
                int isshow = JobRequest.GetRequestInt("isshow"); //是否显示
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                MenuInfo info = new MenuInfo()
                {
                    ID = id,
                    ParentID = parentid,
                    Name = name,
                    Path = path,
                    Btns = btns,
                    Sort = sort,
                    IsShow = isshow
                };
                if (id == 0)
                {
                    ID = MenuDAL.Save(info);
                }
                else
                {
                    ID = MenuDAL.Update(info);
                }
                if (ID > 0)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除菜单
            hs.Add("Delete_Menu", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[menu]");
                if (ok)
                {
                    BtnsDAL.List = BtnsDAL.FindAll();
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*按钮*/
            #region 获取按钮
            hs.Add("Find_Btns", (int adminid) =>
            {
                //参数
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int count = 0;
                List<BtnsInfo> list = BtnsDAL.FindAll();
                dynamic obj = new ExpandoObject();
                obj.list = list;
                obj.count = count;
                return Commons.GetSuccess("获取成功", obj);
            });
            #endregion
            #region 保存按钮
            hs.Add("Save_Btns", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                string name = JobRequest.GetRequestString("name"); //按钮名称
                string method = JobRequest.GetRequestString("method"); //按钮方法
                int sort = JobRequest.GetRequestInt("sort"); //排序
                string color = JobRequest.GetRequestString("color"); //按钮颜色
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                int ID = 0;
                BtnsInfo info = new BtnsInfo()
                {
                    ID = id,
                    Name = name,
                    Method = method,
                    Sort = sort,
                    Color = color
                };
                if (id == 0)
                {
                    ID = BtnsDAL.Save(info);
                }
                else
                {

                    ID = BtnsDAL.Update(info);
                }
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 删除按钮
            hs.Add("Delete_Btns", (int adminid) =>
            {
                //参数
                string ids = JobRequest.GetRequestString("ids"); //删除的id集合,中间用,号隔开
                int source = JobRequest.GetRequestInt("source"); //来源 1.PC  2.Android  3.IOS
                //参数
                bool ok = CommonDAL.DeleteByIDs(ids, "[btns]");
                if (ok)
                {
                    return Commons.GetSuccess("删除成功", "");
                }
                else
                {
                    return Commons.GetFaild("删除失败");
                }
            });
            #endregion

            /*修改配置信息*/
            #region 修改联系我们
            hs.Add("Update_Contact", (int adminid) =>
            {
                //参数
                string comname = JobRequest.GetRequestString("comname"); //
                string contactname = JobRequest.GetRequestString("contactname"); //
                string phone = JobRequest.GetRequestString("phone"); //
                string mobile = JobRequest.GetRequestString("mobile"); //
                string qq = JobRequest.GetRequestString("qq"); //
                string weixin = JobRequest.GetRequestString("weixin"); //
                string sina = JobRequest.GetRequestString("sina"); //
                string email = JobRequest.GetRequestString("email"); //
                double lat = JobRequest.GetRequestDouble("lat"); //
                double lng = JobRequest.GetRequestDouble("lng"); //
                string address = JobRequest.GetRequestString("address"); //
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = adminid,
                    ComName = comname,
                    ContactName=contactname,
                    Phone = phone,
                    Mobile = mobile,
                    QQ = qq,
                    WeiXin = weixin,
                    Sina = sina,
                    Email = email,
                    Lat=lat,
                    Lng=lng,
                    Address=address
                };
                ID = AdminDAL.UpdateContact(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 修改公司介绍
            hs.Add("Update_Introduce", (int adminid) =>
            {
                //参数
                string introduce = JobRequest.GetRequestString("introduce"); //公司介绍
                //参数
                bool ok = CommonDAL.UpdateColumnByID(adminid, "Introduce", introduce, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 修改企业文化
            hs.Add("Update_Culture", (int adminid) =>
            {
                //参数
                string culture = JobRequest.GetRequestString("culture"); //企业文化
                //参数
                bool ok = CommonDAL.UpdateColumnByID(adminid, "Culture", culture, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
            #region 修改版权信息
            hs.Add("Update_Copyright", (int adminid) =>
            {
                //参数
                string copyright1 = JobRequest.GetRequestString("copyright1"); //
                string copyright2 = JobRequest.GetRequestString("copyright2"); //
                string copyright3 = JobRequest.GetRequestString("copyright3"); //
                string copyright4 = JobRequest.GetRequestString("copyright4"); //
                string copyright5 = JobRequest.GetRequestString("copyright5"); //
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = adminid,
                    Copyright1 = copyright1.Replace(" ", "&nbsp;"),
                    Copyright2 = copyright2.Replace(" ", "&nbsp;"),
                    Copyright3 = copyright3.Replace(" ", "&nbsp;"),
                    Copyright4 = copyright4.Replace(" ", "&nbsp;"),
                    Copyright5 = copyright5.Replace(" ", "&nbsp;"),
                };
                ID = AdminDAL.UpdateCopyright(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 修改公司信息
            hs.Add("Update_Cominfo", (int adminid) =>
            {
                //参数
                string comname = JobRequest.GetRequestString("comname"); //
                double lat = JobRequest.GetRequestDouble("lat"); //
                double lng = JobRequest.GetRequestDouble("lng"); //
                string address = JobRequest.GetRequestString("address"); //
                //参数
                int ID = 0;
                AdminInfo info = new AdminInfo()
                {
                    ID = adminid,
                    ComName = comname,
                    Lat = lat,
                    Lng = lng,
                    Address = address
                };
                ID = AdminDAL.UpdateCominfo(info);
                if (ID > 0)
                {
                    return Commons.GetSuccess("保存成功", ID);
                }
                else
                {
                    return Commons.GetFaild("保存成功");
                }
            });
            #endregion
            #region 修改排序
            hs.Add("ReSort", (int adminid) =>
            {
                //参数
                int id = JobRequest.GetRequestInt("id"); //ID
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                string table = JobRequest.GetRequestString("table"); //表
                //参数
                bool ok = CommonDAL.ReSort(id,sort,table);
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改导航菜单
            hs.Add("Update_Menu", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + name, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改首页模块
            hs.Add("Update_Index", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                int tagsid = JobRequest.GetRequestInt("tagsid"); //标签ID
                string newstypeids = JobRequest.GetRequestString("newstypeids"); //资讯分类IDs
                int count = JobRequest.GetRequestInt("count"); //显示数量
                //参数
                bool ok = false;
                if (column == "notice")
                {
                    CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + count + "&" + newstypeids + "&" + name, "[admin]");
                }
                if(column == "environment" || column == "honor")
                {
                    CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + count + "&" + name, "[admin]");
                }
                if (column == "intro" || column == "cult")
                {
                    CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + name, "[admin]");
                }
                if (column == "tags")
                {
                    TagsInfo info = new TagsInfo()
                    {
                        ID = tagsid,
                        Name = name,
                        Count = count,
                        Sort = sort,
                        IsTop = istop
                    };
                    TagsDAL.Edit(info);
                }
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改我们菜单
            hs.Add("Update_We", (int adminid) =>
            {
                //参数
                string column = JobRequest.GetRequestString("column"); //列名
                int sort = JobRequest.GetRequestInt("sort"); //顺序
                int istop = JobRequest.GetRequestInt("istop"); //是否推荐
                string name = JobRequest.GetRequestString("name"); //名字
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, column, sort + "&" + istop + "&" + name, "[admin]");
                if (ok)
                {
                    return Commons.GetSuccess("修改成功", "");
                }
                else
                {
                    return Commons.GetFaild("修改失败");
                }
            });
            #endregion
            #region 修改热门关键词
            hs.Add("Update_Hot", (int adminid) =>
            {
                //参数
                string hot = JobRequest.GetRequestString("hot"); //热门关键词
                //参数
                bool ok = CommonDAL.UpdateColumnByID(B.MyAdmin.ID, "Hot", hot, "[admin]");
                if (ok)
                {
                    B.MyAdmin.Hot = hot;
                    return Commons.GetSuccess("保存成功", "");
                }
                else
                {
                    return Commons.GetFaild("保存失败");
                }
            });
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}